package eu.jpereira.trainings.designpatterns.creational.builder.json;

import java.util.Iterator;

import eu.jpereira.trainings.designpatterns.creational.builder.ReportBodyBuilder;
import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;

public class JSONReportBodyBuilder extends ReportBodyBuilder
{
       
        JSONReportBody reportBody = new JSONReportBody();

        @Override
        public ReportBody getReportBody()
        {
                reportBody.addContent("sale:{customer:{");
                reportBody.addContent("name:\"");
                reportBody.addContent(customerName);
                reportBody.addContent("\",phone:\"");
                reportBody.addContent(phoneNumber);
                reportBody.addContent("\"}");
                reportBody.addContent(",items:[");
                Iterator<Item> it = soldItems.iterator();
                while ( it.hasNext() )
                {
                        Item item = it.next();
                        reportBody.addContent("{name:\"");
                        reportBody.addContent(item.name);
                        reportBody.addContent("\",quantity:");
                        reportBody.addContent(String.valueOf(item.quantity));
                        reportBody.addContent(",price:");
                        reportBody.addContent(String.valueOf(item.price));
                        reportBody.addContent("}");
                        if ( it.hasNext() )
                        {
                                reportBody.addContent(",");
                        }
                       
                }
                reportBody.addContent("]}");
               
                return reportBody;
        }

}
